﻿using Microsoft.Maui.Platform;
using SQLite;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YiMeiJiaLibModel.Business;

namespace YiMeiJiaService.Assembly.DB
{
    public static class YMJLifeSqlite
    {
        public static SQLiteAsyncConnection Database;

        //public YMJLifeSqlite()
        //{
        //}
        // https://learn.microsoft.com/zh-cn/dotnet/maui/data-cloud/database-sqlite

        public static async Task<SQLiteAsyncConnection> Init()
        {
            if (Database is not null)
                return Database;
           
            Database = new SQLiteAsyncConnection(SqliteConf.DatabasePath, SqliteConf.Flags);
            //注册多个Table
            await Database.CreateTableAsync<FMWxAccountCreate>();
            await Database.CreateTableAsync<AdnroidTokens>();
            return Database;
        }


        /// <summary>
        /// 获取数据库
        /// </summary>
        /// <returns></returns>
        public static async Task<SQLiteAsyncConnection> Db()
        {
            return await Init();
        }





        ///// <summary>
        ///// 
        ///// </summary>
        ///// <returns></returns>
        //public async Task<UserInfos> CheckLogin()
        //{
        //    await Init();
        //    return  await Database.Table<UserInfos>().FirstOrDefaultAsync();
        //}

    }
}

